package functionInterface;

import java.util.Random;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class MyConsumer implements Consumer<Integer> {

    @Override
    public void accept(Integer integer) {
        System.out.println(integer);
    }

    /**
     * 默认方法也可以重写
     * @param after
     * @return
     */
    @Override
    public Consumer<Integer> andThen(Consumer<? super Integer> after) {
        return null;
    }

    /**
     * java8提供几个常用函数式接口
     * @param args
     */
    public static void main(String[] args) {

        Consumer<Integer> consumer = (Integer i) -> System.out.println(i);
        Predicate<String> predicate = (String str) -> str.isEmpty();
        Function<String, Integer> function = (String str) -> Integer.parseInt(str);
        Supplier<Integer> supplier = () -> new Random().nextInt();

        consumer.accept(10);
        System.out.println(predicate.test("123"));
        System.out.println(function.apply("9999"));
        System.out.println(supplier.get());
    }
}
